package data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.GregorianCalendar;

public class JDBCAnuncioDAO implements IAnuncioDAO {


	
	
	public JDBCAnuncioDAO(){
	}
	
	

		@Override
		public void insertAnuncio(int idMascota, int idLugar, String comentario){
			Connection conn = ConnectionManager.getInstance().CheckOut();
			PreparedStatement stmt = null;
			String sql = "INSERT INTO `anuncio` (`ID_MASCOTA`, `ID_LUGAR`, `FECHA_HORA`, `CONTENT`) VALUES (?, ?, ?, ?)";
			
			try {
				stmt = conn.prepareStatement(sql);
				stmt.setInt(1,idMascota );
				stmt.setInt(2,idLugar );
				long milisegundos = GregorianCalendar.getInstance().getTimeInMillis();
				stmt.setDate(3, new java.sql.Date(milisegundos));
				stmt.setString(4, comentario);
				
				
				stmt.executeUpdate();
	        } catch (SQLException e) {
	            System.out.println("Message: " + e.getMessage());
	            System.out.println("SQLState: " + e.getSQLState());
	            System.out.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	        	ConnectionManager.getInstance().CheckIn(conn);
	            try {
	                if (stmt != null) {
	                    stmt.close();
	                }
	            } catch (SQLException e) {
	            }
	        }
		}
	
}
